{extend name="public/base" /}

{block name="title"}
<title>楼盘信息</title>
{/block}

{block name="pjax_container"}
<section class="content-header">
    <h1>楼盘信息</h1>
    <ol class="breadcrumb">
        <li class="active"><i class="fa fa-dashboard"></i> 楼盘信息</li>
    </ol>
</section>
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <form class="form-horizontal" method="POST" action="{:url('houses_edit')}" onsubmit="return false" >
                <div class="nav-tabs-custom">
                    <ul class="nav nav-tabs">
                        <li class="pull-right"><a href="javascript:history.back(-1)" class="btn btn-sm" style="padding:10px 2px;"> </a></li>
                    </ul>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">楼盘名称</label>
                        <div class="col-sm-7"><input class="form-control" type="text" name="name" value="{$data.name}"/></div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">顶部轮播图片</label>
                        <div class="col-sm-7 upload-box">
                            <div class="image-box clear">
                                {volist name="$data['imgs']" id="v"}
                                <section class="image-section">
                                    <div class="image-shade"></div>
                                    <div class="image-delete"></div>
                                    <img class="image-show" src="{$v}" />
                                    <input name="imgs[]" value="{$v}" type="hidden" />
                                </section>
                                {/volist}
                                <section class="upload-section">
                                    <div class="upload-btn"></div>
                                    <input type="file" name="file" set-name="imgs" id="upload-input" value=""/>
                                </section>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">楼盘房型</label>
                        <div class="col-sm-7 my_uploads" style="border:1px solid blanchedalmond;">
                            {foreach name="$data.house_type" item="vo" key="ko"}
                                <div class="child_my_uploads" style="margin-bottom:30px;">
                                    <input class="form-control" type="text" name="house_type_title[]" value="{$vo[0]}" placeholder="房型名称"/>
                                    <input class="form-control" type="hidden" name="house_type_img[]" value="{$vo[1]}"/>
                                    <a href="{$vo[1]}" target="_blank"><img src="{$vo[1]}" style="width:100px;height:100px;"/></a>
                                    <input type="file" name="file" class="layui-upload-file" id="myupload">
                                    <button class="layui-btn layui-btn-small layui-btn-danger" onclick="remove_house(this)">删除房型</button>
                                </div>
                            {/foreach}
                            <button type="button" class="layui-btn" style="width:100%;" onclick="add_house(this)">添加房型</button>
                        </div>
                    </div>

                    <div class="copy_upload" style="display:none;">
                        <div class="child_my_uploads" style="margin-bottom:30px;">
                            <input class="form-control" type="text" name="house_type_title[]" value="" placeholder="房型名称"/>
                            <input class="form-control" type="hidden" name="house_type_img[]" value=""/>
                            <a href="" target="_blank"><img src="" style="width:100px;height:100px;"/></a>
                            <input type="file" name="file" class="layui-upload-file" id="myupload">
                            <button class="layui-btn layui-btn-small layui-btn-danger" onclick="remove_house(this)">删除房型</button>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">价格</label>
                        <div class="col-sm-7"><input class="form-control" type="text" name="price" value="{$data.price}"/></div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">开发商</label>
                        <div class="col-sm-7"><input class="form-control" type="text" name="developers" value="{$data.developers}"/></div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">地址</label>
                        <div class="col-sm-7"><input class="form-control" type="text" name="addr" value="{$data.addr}"/></div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">电话</label>
                        <div class="col-sm-7"><input class="form-control" type="text" name="tel" value="{$data.tel}"/></div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">简介</label>
                        <div class="col-sm-7"><input class="form-control" type="text" name="desc" value="{$data.desc}"/></div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-2 control-label">详情</label>
                        <div class="col-sm-7">
                            <textarea name="content" cols="133" rows="8">{$data.content}</textarea>
                        </div>
                    </div>

                    <div class="box-footer">
                        <div class="col-sm-2"></div>
                        <div class="col-sm-7">
                            <div class="btn-group pull-right">
                                <button type="submit" class="btn btn-info pull-right submits" data-loading-text="&lt;i class='fa fa-spinner fa-spin '&gt;&lt;/i&gt; 提交">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</section>
<script type="application/javascript">
    $("#upload-input").ajaxImageUpload({
        url: "{:url('File/store')}", //上传的服务器地址
        // data: { name:'勾国印' },
        data:{},
        maxNum: 5, //允许上传图片数量
        zoom: false, //允许放大
        allowType: ["gif", "jpeg", "jpg", "bmp",'png','zip'], //允许上传图片的类型
        maxSize :2, //允许上传图片的最大尺寸，单位M
        callbackFieldName:'saveName',
        before: function () {
            // alert('上传前回调函数');
        },
        success:function(data){
            // alert('上传成功回调函数');
            // console.log(data);
        },
        error:function (e) {
            // alert('上传失败回调函数');
            // console.log(e);
        }
    });

    var copy_html = $('.copy_upload').html();

    function add_house(obj){
        $(obj).before(copy_html);
        each_upload()
    }

    function remove_house(obj){
        $(obj).parent().remove();
        each_upload()
    }

    function each_upload(){
        $('.my_uploads .child_my_uploads').each(function(index,element){
            $(element).find('input[name=file]').attr('id', 'myupload'+index);
            init_upload('#myupload'+index);
        });
    }

    function init_upload(id){
        layui.use('upload', function(){
            layui.upload({
                elem: id,
                url: "{:url('File/store')}"
                ,success: function(res){
                    $(id).parents('.child_my_uploads').find('input[name*=house_type_img]').val(res.data.saveName);
                    $(id).parents('.child_my_uploads').find('a').attr('href', res.data.saveName);
                    $(id).parents('.child_my_uploads').find('img').attr('src', res.data.saveName);
                },
                before: function(input){
                    $('.layui-upload-button form').submit(function(event){
                        event.stopPropagation();
                    });
                }
            });
        });
    }

    each_upload();


</script>
{/block}